package cn.lyjuan.dwz_manage.core.java.action;


import cn.lyjuan.dwz_manage.core.base.pojo.ActionGroupPojo;
import cn.lyjuan.dwz_manage.core.java.dto.QueryResultBean;
import cn.lyjuan.dwz_manage.core.java.service.ActionGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by ly on 2015/3/3.
 */
@Controller
@RequestMapping("group/")
public class ActionGroupAction extends BaseAction
{

    @Autowired
    @Qualifier("mgActionGroupService")
    private ActionGroupService actionGroupSer;

    /**
     * 选择组
     * @return
     */
    @RequestMapping("selectGroup")
    public void selectGroup(HttpServletRequest req)
    {
        Map<String, String> param = this.paramsToMap();
        // 搜索组
        QueryResultBean<ActionGroupPojo> bean = actionGroupSer.queryGroups(param, this.getDwzPn(), this.getDwzPs());

        this.pkgManagePage(bean.getTotalCount());
        req.setAttribute("groups", bean.getList());
    }

    /**
     * 查询组
     * @return
     */
    @RequestMapping("groupList")
    public void groupList(HttpServletRequest req)
    {
        Map<String, String> param = this.paramsToMap();
        // 搜索组
        QueryResultBean<ActionGroupPojo> bean = actionGroupSer.queryGroups(param, this.getDwzPn(), this.getDwzPs());

        this.pkgManagePage(bean.getTotalCount());
        req.setAttribute("groups", bean.getList());
    }

    /**
     * 增加组信息
     * @return
     */
    @RequestMapping("addGroup")
    @ResponseBody
    public void addGroup(ActionGroupPojo group, HttpServletRequest req, HttpServletResponse resp)
    {
        actionGroupSer.addGroup(group);

        this.returnDwzAjaxSucc();
    }

    /**
     * 请求修改组页面
     * @return
     */
    @RequestMapping("preUpdateGroup")
    public void preUpdateGroup(HttpServletRequest req, int id)
    {
        ActionGroupPojo group = actionGroupSer.queryGroupById(id);

        req.setAttribute("group", group);
    }

    /**
     * 修改组信息
     * @param req
     * @return
     */
    @RequestMapping("updateGroup")
    @ResponseBody
    public void updateGroup(ActionGroupPojo group, HttpServletRequest req, HttpServletResponse resp)
    {
        actionGroupSer.updateActionGroup(group);

        this.returnDwzAjaxSucc();
    }

    /**
     * 锁定组
     * @return
     */
    @RequestMapping("lockGroup")
    @ResponseBody
    public void lockGroup(HttpServletRequest req, HttpServletResponse resp, int id)
    {
        actionGroupSer.lockGroup(id);

        this.returnDwzAjaxSucc();
    }
}
